<template>
  <div class="box">
    <div class="head">
      <van-icon class="arrow-left" name="arrow-left" @click="goBack" /> 个人中心
      <van-icon class="setting" name="setting" @click="goset" />
    </div>
    <div class="content">
      <div class="reg">
        <div class="userimg">
          <img src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg" />
        </div>
        <div @click="goLogin">您好：{{ msg }}</div>
      </div>
      <van-grid>
        <van-grid-item icon="gold-coin-o" text="待付款" />
        <van-grid-item icon="shop-o" text="待收货" />
        <van-grid-item icon="thumb-circle-o" text="待评价" />
        <van-grid-item icon="label-o" text="全部订单" />
      </van-grid>

      <van-cell title="地址管理" is-link @click="goArea"/>
      <van-cell title="我的收藏夹" is-link />
      <van-cell title="关于我们" is-link />
      <img class="logo" src="../assets/logo.png" />
    </div>

    <FooterVue class="footer"></FooterVue>
  </div>
</template>

<script>
import FooterVue from "@/components/Footer.vue";

export default {
  name: "My",
  components: {
    FooterVue,
  },
  data() {
    return {
      msg: "请先登录",
    };
  },
  methods: {
    goLogin() {
      this.$router.push("/Login");
    },
    goBack() {
      this.$router.back();
    },
    goset(){
      this.$router.push("/Sets")
    },
    goArea(){
      this.$router.push("/Address")
    }
  },
  created() {
    let token = localStorage.getItem("token");
    let userid = localStorage.getItem("userid");
    this.$server({
      url:"/api/user/info",
      params:{
        userid: userid,
      },
      headers: {
          "token": token,
        },
    })
      .then((res) => {
        console.log("res.data", res.data);
        if (res.data.code == 200) {
          res.data.data[0].username == ""
            ? (this.msg = res.data.data[0].tel)
            : (this.msg = res.data.data[0].username);
        }
      });
  },
};
</script>

<style scoped>
.box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: #efefef;
}

.head {
  height: 45px;
  background-color: skyblue;
  text-align: center;
  line-height: 45px;
}
.arrow-left {
  float: left;
  margin: 1rem;
}
.setting {
  margin: 1rem;
  float: right;
}
.content {
  flex: 1;
  overflow: auto;
}
.reg {
  height: 6rem;
  line-height: 6rem;
  background-color: pink;
  display: flex;
  align-items: center;
}

.userimg {
  height: 5rem;
  width: 5rem;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 2rem;
}
.userimg img {
  width: 100%;
  height: 100%;
}
.goods-serve {
  background-color: #fff;
  height: 5.5rem;
}
.goods-serve li {
  float: left;
  width: 25%;
  height: 100%;
  box-sizing: border-box;
  border-bottom: 0.5px solid rgb(237, 233, 233);
  border-right: 0.5px solid rgb(237, 233, 233);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.goods-serve li span {
  margin-top: 0.5rem;
}
.goods-serve li:last-child {
  border-right: 0;
}
.logo {
  width: 2.5rem;
  margin: 1rem auto;
  display: block;
}
</style>
